package com.javaBasic;

import java.util.*;

public class DemoCollection {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("123");
        Collection<String> clist = Collections.unmodifiableCollection(list);
        list.add("345");
        //clist.add("aaa");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        System.out.println(list);


        Map hashMap = new HashMap();
// 增加元素
        hashMap.put("name", "老王");
        hashMap.put("age", "30");
        hashMap.put("sex", "你猜");
// 删除元素
        hashMap.remove("age");
// 查找单个元素
        System.out.println(hashMap.get("age"));
// 循环所有的 key

        for (Object k : hashMap.keySet()) {
            System.out.println(k);
        }
// 循环所有的值
        for (Object v : hashMap.values()) {
            System.out.println(v);
        }
    }
}
